package org.nf.web.view;

import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletResponse;
import org.nf.web.servlet.ServletApi;
import org.nf.web.servlet.View;

import java.io.IOException;

/**
 * @Author lzp
 * @Date 2024-05-20
 * 重定向视图
 */
public class RedirectView implements View {

    /**
     * 重定向地址
     */
    private final String url;

    public RedirectView(String url) {
        this.url = url;
    }

    @Override
    public void render(ServletApi api) throws ServletException, IOException {
        HttpServletResponse resp = api.response();
        resp.sendRedirect(url);
    }
}
